package cn.edu.sjtu.stap.sdg.builder;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;


import cn.edu.sjtu.stap.cfg.ControlFlowGraph;
import cn.edu.sjtu.stap.sdg.SystemDependenceGraph;

public class IntraSdgBuilder {

    private HashMap<AbstractMethodDeclaration, SystemDependenceGraph> sdgs = new HashMap<AbstractMethodDeclaration, SystemDependenceGraph>();

    /**
     * Towards the intra-Method view.
     * 
     * Steps: 1. use the nodes from cfg 
     *           2. query the edges from cfg and add
     * sdgEdge to the wrapped nodes.
     */

    public void buildIntraSdg(
            Map<AbstractMethodDeclaration, ControlFlowGraph> cfgs) {
        Set cfgEntrySet = cfgs.keySet();
        Iterator cfgEntryIterator = cfgEntrySet.iterator();

        while (cfgEntryIterator.hasNext()) {
            AbstractMethodDeclaration item = (AbstractMethodDeclaration) cfgEntryIterator.next();
            ControlFlowGraph intraCfg = cfgs.get(item);
            //core: wrap node and transfer edges for the intraSDG.
            SystemDependenceGraph sdg = new SystemDependenceGraph(item, intraCfg);
            //store the result
            sdgs.put(item, sdg);
        }
    }
    
    public Map<AbstractMethodDeclaration, SystemDependenceGraph> getResults() {
        return sdgs;
    };

}
